<template>
    <div style="text-align: center">
        <div>
            <van-nav-bar fixed="true" title="修改信息" left-text="返回" left-arrow="" @click-left="onClickLeft">
            </van-nav-bar>
        </div>
        <van-cell-group style="margin-top: 46px">
            <div>
                <span>选择律师头像</span>
            </div>
            <van-radio-group v-model="image" direction="horizontal" style="justify-content: center">
                <van-radio name="../../static/images/nan.png" icon-size="24px"><img src="../../static/images/nan.png"
                                                                                    width="50" height="50"
                                                                                    style="border-radius: 50%">
                </van-radio>
                <van-radio name="../../static/images/nv.png" icon-size="24px"><img src="../../static/images/nv.png"
                                                                                   width="50" height="50"
                                                                                   style="border-radius: 50%">
                </van-radio>
            </van-radio-group>
            <van-field
                    label-align="right"
                    readonly
                    clickable
                    name="picker"
                    :value="kind"
                    label="律师类别"
                    placeholder="点击选择律师类别"
                    @click="showPicker = true"
            />
            <van-popup v-model="showPicker" position="bottom">
                <van-picker
                        show-toolbar
                        :columns="columns"
                        @confirm="onConfirm"
                        @cancel="showPicker = false"
                />
            </van-popup>
            <van-field
                    style="margin-top: 10px"
                    v-model="lawyername"
                    required
                    label="用户名"
                    placeholder="请修改用户名"
            />

            <van-field
                    v-model="lawyersex"
                    required
                    label="性别"
                    placeholder="请修改性别"
            />
            <van-field
                    v-model="lawyerage"
                    required
                    label="年龄"
                    placeholder="请修改年龄"
            />
            <van-field
                    v-model="lawyernumber"
                    required
                    label="账号"
                    placeholder="请修改账号"
            />
            <van-field
                    v-model="lawLawyerPwd"
                    required
                    label="密码"
                    placeholder="请修改密码"
            />
        </van-cell-group>
            <van-button @click="lawyerChangeMessage" style="margin-top: 10px" size="small"
                        color="linear-gradient(to right, #4bb0ff, #6149f6)" round
                        type="info">提交修改
            </van-button>
    </div>
</template>

<script>
    export default {
        name: "lawyerChangeMessage",
        data() {
            return {
                showPicker: false,
                kind: '',
                image: '',
                columns: ['行政律师', '经济律师', '民事律师', '刑事律师'],
                lawyername: '',
                lawyersex: '',
                lawyerage: '',
                lawyernumber: '',
                lawLawyerPwd: ''
            }
        },
        methods: {
            onConfirm(value) {
                this.value = value;
                this.showPicker = false;
            },
            onClickLeft() {
                this.$router.push({path: 'lawyerMessage'})
            },
            lawyerChangeMessage() {
                console.log(this.lawyername)
                console.log(this.lawyersex)
                console.log(this.kind)
                console.log(this.number)
                console.log(this.lawLawyerPwd)
                console.log(this.image)
                console.log(this.lawyerage)
                let lawyer = JSON.parse(localStorage.getItem('token') || '{}');
                if (!this.lawyernumber) {
                    this.$toast.fail('必须填写账号!')
                } else if (!this.lawLawyerPwd) {
                    this.$toast.fail('必须填写密码！')
                } else{
                    this.$axios.post('/lawyer/updateLawyer', {
                            "lawLawyerImage": this.image,
                            "lawLawyerKind": this.kind,
                            "lawLawyerName": this.lawyername,
                            "lawLawyerNumber": this.lawyernumber,
                            "lawLawyerSex": this.lawyersex,
                            "lawLawyerAge": this.lawyerage,
                            "lawLawyerPwd": this.lawLawyerPwd,
                            "id": lawyer.id
                        },
                        res => {
                            console.log(res)
                            if (res.data.success) {
                                this.$axios.post('/lawyer/showLawyer', {id: lawyer.id},
                                    res => {
                                        if (res.data.success) {
                                            localStorage.setItem('token', JSON.stringify(res.data.data))
                                        }
                                    })
                                this.$toast.success('修改成功！')
                                this.$router.push('/lawyerCenter')

                            } else {
                                this.$toast(res.data.message)
                            }
                        })
                }
            }
        }
    }
</script>


<style scoped>

</style>
